<?php

			
require_once "inc/setup.php";
require_once "inc/user.class.php";
require_once "inc/imageHashManager.class.php";

$user = new User();

try{
$user->auth();
}
catch(Exception $e){$user = User::createAnon();}

if(isset($_GET['out']))
{
	$user = User::logout();
	header("Location: login.php");exit;
}

if($_POST)
{
	try{
	$user = User::login($_POST['login'], $_POST['pass']);
	header("Location: login.php");exit;
	}
	catch(Exception $e){}

}
else
{
if($user->isAnon())
{
	?>
<form method="post">
Login: <input type="text" name="login" /> <br />
Pass: <input type="password" name="pass" /> <br />
<input type="submit" value="login" />
</form>
	<?
}
else
{
	echo $user->user_name;
	echo " <a href='?out'>Logout</a>";
	//print_r(Base::massload("user", "id>0"));
	$img = new imageHashManager();
	$img->readImageFile("./bg.jpg");
	$hash = $img->createHash();
	try {
		$img->save();
	} catch (Exception $e) {
		echo($e->getMessage());
	}	
}

}